﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WTwitter.Model.Utility;
using WTwitter.Model.UserData;
using WTwitter.Model.Twitter.Json;
using System.Net;
using System.Web;

namespace WTwitter.Model.Twitter.Utility {
	public static class AccountMethod {
		private static readonly string VerifyCredentialsUrl = "http://api.twitter.com/1/account/verify_credentials.json";
		private static readonly string RateLimitStatusUrl = "http://api.twitter.com/1/account/rate_limit_status.json";


		public static User VerifyCredential(AuthInfo info) {
			User result = null;
			try {
				result = WebUtility<User>.GetDeserializedJsonData(VerifyCredentialsUrl, "GET", new RequestParameter[] { }, info);
			} catch (WebException e) {
				var status = e.Response as HttpWebResponse;
				if (status.StatusCode == HttpStatusCode.Unauthorized) {
					throw new AuthorizationFailedException("認証に失敗しました。オプションで設定してください");
				} else {
					throw e;
				}
			}
			return result;
		}

		public static Hash RateLimitStatus(AuthInfo info) {
			return WebUtility<Hash>.GetDeserializedJsonData(RateLimitStatusUrl, "GET", new RequestParameter[] { }, info);
		}
	}
}
